package com.zl.tcbnewcar.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.zl.tcbnewcar.R;
import com.zl.tcbnewcar.base.BaseActivity;
import com.zl.tcbnewcar.view.LocalIntegerImageHolderView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanglei
 * @date 17/8/6
 * 欢迎页
 */
public class WelComeActivity extends BaseActivity {

    private final int[] images = {R.mipmap.image1, R.mipmap.image3, R.mipmap.image2};
    private ConvenientBanner viewPager;
    private List<Integer> mList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //取消状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_wel_come);
        initView();
        initData();
        initListener();
    }

    private void initListener() {
        viewPager.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                if (position == (mList.size() - 1)) {
                    startActivity(new Intent(mActivity, MainActivity.class));
                    finish();
                }
            }
        });
    }

    private void initData() {
        for (int image : images) {
            mList.add(image);
        }
        viewPager.notifyDataSetChanged();
    }

    private void initView() {
        viewPager = (ConvenientBanner) findViewById(R.id.wel_viewPager);
        viewPager.setPages(new CBViewHolderCreator<LocalIntegerImageHolderView>() {
            @Override
            public LocalIntegerImageHolderView createHolder() {
                return new LocalIntegerImageHolderView();
            }
        }, mList);
        viewPager.setCanLoop(false);
    }
}
